package  wibrst.utils{
	import flash.display.LoaderInfo;
	import flash.system.Capabilities;
	import flash.utils.getQualifiedClassName;
	/**
	 * ...
	 * @author wibrst@qq.com
	 */
	public class EnvUtil {
		
		static public function getClassName( inst:* ):String {
			var aNameSplit:Array = getQualifiedClassName( inst ).split(":");
			return aNameSplit[ aNameSplit.length - 1];
		}
	
		static public function checkSelfHost( loaderInfo:LoaderInfo ):Boolean {
			trace( '[CommUtils] checkSelfHost -- ',
				'\n\tloaderInfo.url:', loaderInfo.url,
				'\n\tloaderInfo.loaderURL:', loaderInfo.loaderURL
			);
			if ( loaderInfo.loader && loaderInfo.loader.loaderInfo ) trace(
				'\n\tloaderInfo.loader.loaderInfo.url:', loaderInfo.loader.loaderInfo.url,
				'\n\tloaderInfo.loader.loaderInfo.loaderURL:', loaderInfo.loader.loaderInfo.loaderURL
			);
			
			if ( loaderInfo.url == loaderInfo.loaderURL ) return true;
			else if ( loaderInfo.url.indexOf( '[[DYNAMIC]]' ) != -1 ) return checkSelfHost( loaderInfo.loader.loaderInfo );
			else return false;
		}
		
		static public function getLoaderPara( loaderInfo:LoaderInfo, sName:String, sDefValue:String = "[NONVALUE]" ):String {
			var sRet:String;
			var paramsFlashVars:Object = loaderInfo.parameters;
			if ( paramsFlashVars[ sName ] && (paramsFlashVars[ sName ] as String).length ) {
				sRet =  paramsFlashVars[ sName ];
				trace( "[EnvUtil] getLoaderPara <" + sName + "> have value:(" + sDefValue + ")" );
			}else {
				sRet = sDefValue;
				trace( "[EnvUtil] getLoaderPara <" + sName + "> no value, use defalt:(" + sDefValue + ")" );
			}
			return sRet;
		}
	
		static public function checkInBrowser():Boolean {
			
			switch(Capabilities.playerType){
				case "StandAlone":
				case "External":
					return false;
				break;
				case "PlugIn":
				case "ActiveX":
					return true;
				break;
			}
			
			return false;
		}
	}

}